﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Timers;

namespace Scheduler {


    public class Execute {

        DiscoveryBuffer db = new DiscoveryBuffer();
        SenderBuffer sb = new SenderBuffer();
        int count = 0;

        private ArrayList senderList = new ArrayList();
        private ArrayList discoveryList = new ArrayList();


        public void run() {

            String[] data = { "qwert", "asdfg" };
            String[] dataInter = { "1234", "4566" };
            String[] disc = { "mac1", "mac2" };

            DiscoveryBuffer db = new DiscoveryBuffer();

            SenderBuffer sb = new SenderBuffer();
            SenderBuffer sb1 = new SenderBuffer();

            SenderBuffer sbInter1 = new SenderBuffer();
            SenderBuffer sbInter2 = new SenderBuffer();

            sb.addNewPacket(data, Priority.HIGH_PRIORITY);
            sb1.addNewPacket(data, Priority.HIGH_PRIORITY);

            sbInter1.addNewPacket(dataInter, Priority.LOW_PRIORITY);
            sbInter2.addNewPacket(dataInter, Priority.LOW_PRIORITY);

            db.addNewPacket(disc, Priority.HIGH_PRIORITY);

            addDataPacket(sb, PacketType.SENDER);
            addDataPacket(sb1, PacketType.SENDER);

            addDataPacket(sbInter1, PacketType.SENDER);
            addDataPacket(sbInter2, PacketType.SENDER);

            addDataPacket(db, PacketType.DISCOVERY);
                    
        }



        public object getNextPacket() {

            Object dp = null;

            do {


                if (senderList.Count > 0) {
                    Console.WriteLine("sending");
                    Console.Read();
                    dp = ((SenderBuffer)senderList[0]).getNextData();
                    senderList.RemoveAt(0);
                }

                Console.WriteLine("receving5 sec");// Thread Sleep
                Console.Read();
                dp = new object();

                if (senderList.Count > 0) {
                    Console.WriteLine("sending");
                    Console.Read();
                    dp = ((SenderBuffer)senderList[0]).getNextData();
                    senderList.RemoveAt(0);
                }

                Console.WriteLine("receiving5 sec");// Thread Sleep
                Console.Read();
                dp = new object();

                if (discoveryList.Count > 0) {
                    Console.WriteLine("discover");
                    Console.Read();
                    dp = ((DiscoveryBuffer)discoveryList[0]).getNextData();
                    discoveryList.RemoveAt(0);
                }

            } while (dp != null);

            return dp;
        }

        public void addDataPacket(object dataPacket, PacketType packetType) {

            switch (packetType) {

                case PacketType.SENDER:

                    senderList.Add(dataPacket);
                    break;

                case PacketType.DISCOVERY:

                    discoveryList.Add(dataPacket);
                    break;

                default:
                    break;
            }

        }
    }

    public enum PacketType {

        SENDER,
        DISCOVERY
    }

}
